package cn.bgs.service.impl;

import cn.bgs.common.R;
import cn.bgs.pojo.InvestmentPolicy;
import cn.bgs.mapper.InvestmentPolicyMapper;
import cn.bgs.service.InvestmentPolicyService;
import cn.bgs.vo.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 招商政策表 服务实现类
 * </p>
 *
 * @author Mr.Zhao
 * @since 2022-08-08
 */
@Service
public class InvestmentPolicyServiceImpl extends ServiceImpl<InvestmentPolicyMapper, InvestmentPolicy> implements InvestmentPolicyService {

    @Autowired
    private InvestmentPolicyMapper investmentPolicyMapper;

    @Override
    public R findInvestmentPolicy(String inPoInfo,String inPoCompany) {

        List<InvestmentPolicy> investmentPolicyList = investmentPolicyMapper.findInvestmentPolicy(inPoInfo, inPoCompany);

        return R.ok().data("investmentPolicyList",investmentPolicyList);
    }

    @Override
    public R findInvestmentPolicyId(Integer id) {

        InvestmentPolicy investmentPolicy = investmentPolicyMapper.findInvestmentPolicyId(id);

        return R.ok().data("investmentPolicy",investmentPolicy);
    }

    @Override
    public R addInvestmentPolicy(InvestmentPolicy investmentPolicy) {

        investmentPolicy.setInPoNumber(RandomUtil.getSixBitRandom());

        Integer i = investmentPolicyMapper.addInvestmentPolicy(investmentPolicy);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","新增失败");
        }
    }

    @Override
    public R updateInvestmentPolicy(InvestmentPolicy investmentPolicy) {

        Integer i = investmentPolicyMapper.updateInvestmentPolicy(investmentPolicy);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","编辑失败");
        }

    }

    @Override
    public R delInvestmentPolicy(Integer id) {

        InvestmentPolicy investmentPolicy = investmentPolicyMapper.findInvestmentPolicyId(id);

        investmentPolicy.setDeleteFlag(1);

        Integer i = investmentPolicyMapper.updateInvestmentPolicy(investmentPolicy);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","删除失败");
        }

    }
}
